package de.baumann.browser.adapter;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.math.BigDecimal;

import de.baumann.browser.OdinGlideModule;
import de.baumann.browser.R;
import de.baumann.browser.api.net.vo.LoginInfo;
import de.baumann.browser.utils.StringUtil;

/**
 * @author:
 * @date:2018/12/13 17:38
 * @discription: 算力排名适配器
 */
public class HashRankingAdapter extends BaseQuickAdapter<LoginInfo, BaseViewHolder> {
    public HashRankingAdapter(int layoutResId) {
        super(layoutResId);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void convert(BaseViewHolder helper, LoginInfo item) {
        TextView tvRankingNum = helper.getView(R.id.tvRankingNum);
        ImageView ivRankingHead = helper.getView(R.id.ivRankingHead);
        TextView tvRankingPhone = helper.getView(R.id.tvRankingPhone);
        TextView tvRankingHash = helper.getView(R.id.tvRankingHash);

        tvRankingNum.setText(String.valueOf(helper.getLayoutPosition()+4));
        if (TextUtils.isEmpty(item.getPhone())){
            tvRankingPhone.setText(StringUtil.emailHide(item.getLoginName()));
        }else{
            tvRankingPhone.setText(StringUtil.mobileHide(item.getPhone()));
        }

        BigDecimal bigDecimal = new BigDecimal(item.getContribute());
        tvRankingHash.setText(bigDecimal.setScale(4,BigDecimal.ROUND_HALF_UP).toString());
        OdinGlideModule.loadWithCropAndCircle(mContext,item.getHeadUrl(),ivRankingHead,R.drawable.icon_head);
    }
}
